import 'package:find_friend/const/const.dart';
import 'package:find_friend/pages/im/pages/conversation_list_page.dart';
import 'package:find_friend/pages/xspace/post/xpost_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'custompage/msg_friend_page.dart';
import 'custompage/msg_group_friend_page.dart';
import 'custompage/msg_receive_page.dart';

class MessagePage extends StatefulWidget {
  @override
  _MessagePageState createState() => _MessagePageState();
}

class _MessagePageState extends State<MessagePage> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController _tabController;
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  int currentTabbar = 0;
  PageController _pageController = PageController(initialPage: 0);
  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: 3, vsync: this,);
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void dispose() {
    _tabController.dispose();
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      resizeToAvoidBottomPadding: false,
      backgroundColor: APP_scaffold_back_color,
      appBar: AppBar(
        centerTitle: true,
        title: Text("联系人",),
        leading: Container(),
        actions: [
          InkWell(
            onTap: () => Navigator.pushNamed(context, '/search'),
            child: Image.asset("assets/sousuo.png", width: 30,color: Colors.black,)
          ),
          InkWell(
            onTap: (){
              // Navigator.of(context).push(CupertinoPageRoute(builder: (context) => XPostPage()));
              push(context, XPostPage());
            },
            child: Image.asset("assets/fabu2.png", width: 30,),
          )
        ],
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(colors: [
              const Color(0xFFffe92e),
              const Color(0xFFfbd001),
            ], begin: Alignment(-1.5,0.5), end: Alignment(0, 0)),
          ),
        ),
      ),
      body: Column(
        children: [
          Container(
            color: Colors.white,
            height: 40.h,
            padding: const EdgeInsets.symmetric(horizontal: 20),
            child: TabBar(
                  controller: _tabController,
                  labelColor: APP_font_black,
                  unselectedLabelColor: const Color(0xff666666),
                  labelStyle: instanceTextStyle(17, APP_font_black),
                  unselectedLabelStyle: instanceTextStyle(14, const Color(0xff666666)),
                  indicatorColor: APP_main_color,
                  indicatorPadding: const EdgeInsets.only(left: 30, right: 30),
                  onTap: (index){
                    setState(() {
                      currentTabbar = index;
                    });
                    _pageController.jumpToPage(index);
                  },
                  tabs: [
                    Text("我的消息", style: currentTabbar == 0 ? instanceTextStyle(17, APP_font_black) : instanceTextStyle(14, const Color(0xff666666)),),
                    Text("我的好友", style: currentTabbar == 1 ? instanceTextStyle(17, APP_font_black) : instanceTextStyle(14, const Color(0xff666666)),),
                    Text("我的分组", style: currentTabbar == 2 ? instanceTextStyle(17, APP_font_black) : instanceTextStyle(14, const Color(0xff666666)),),
                  ],
                ),
          ),
          Expanded(
            child: PageView(
              physics: const ClampingScrollPhysics(), // 关闭回弹效果
              controller: _pageController,
              onPageChanged: (index){
                _tabController.animateTo(index);
                setState(() {
                  currentTabbar = index;
                });
              },
              children: [
                MsgHomePage(),
                MsgFriendPage(),
                MsgGroupFriendPage(),
              ],
            ),
          )
        ],
      ),
    );
  }
}